package com.ruoyi.system.controller;

import com.ruoyi.system.domain.dto.UserDto;
import com.ruoyi.system.domain.vo.AllBillListVo;
import com.ruoyi.system.domain.vo.BillInfoVo;
import com.ruoyi.system.domain.vo.BillListVo;
import com.ruoyi.system.service.ElecImportService;
import com.ruoyi.system.service.IBillInfoService;
import com.ruoyi.system.utils.MyMath;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author xy
 * @version 1.0
 * @description:
 * @date 2024/7/4 9:24
 */
@RestController
@RequestMapping("/system/bill")
@Api(tags = "用电账单模块")
public class BillController {
    /**
     * 账单业务
     */
    @Autowired
    private IBillInfoService billInfoService;

    /**
     * 用电报告业务
     */
    @Autowired
    private ElecImportService elecImportService;

    @GetMapping("/info")
    @ApiOperation("查询账单详情")
    public BillInfoVo getBillInfo(@ApiParam(name = "billInfoId", value = "账单详情ID") @RequestParam("billInfoId") Long billInfoId) {
        BillInfoVo billInfoVo = billInfoService.selectBillInfo(billInfoId);
        float payAmount = MyMath.getPayAmount(billInfoVo.getLastUsage(), billInfoVo.getNowUsage());
        billInfoVo.setPayAmounts(payAmount);
        return billInfoVo;
    }

    @PostMapping("/add")
    @ApiOperation("新增账单详情")
    public int addBillInfo(@RequestBody UserDto userDto) {
        Long userId = userDto.getUserId();
        return billInfoService.insertBillInfo(userId);
    }

    @GetMapping("/list")
    @ApiOperation("查询用户账单列表")
    public List<BillListVo> getBillList(@ApiParam(name = "userId", required = false) @RequestParam("userId") Long userId) {
        return billInfoService.selectBillList(userId);
    }

    @GetMapping("/allList")
    @ApiOperation("查询所有用户账单列表")
    public List<AllBillListVo> getAllBillList() {
        return billInfoService.selectAllBillList();
    }

    @GetMapping("/isPaid")
    @ApiOperation("查询用户上个月账单支付情况")
    public boolean selectUserLastBillIsPaid(@RequestParam("userId") Long userId) {
        return billInfoService.selectUserLastBillIsPaid(userId);
    }

    @GetMapping("/last")
    @ApiOperation("查询用户上个月账单详情")
    public BillListVo selectUserLastBillAmounts(@RequestParam("userId") Long userId) {
        return billInfoService.selectUserLastBillInfo(userId);
    }
}
